package adapter

//import "_ github.com/mattn/go-sqlite3"

/*
所有SQL语句使用小写,大小写敏感的数据库,其对应的数据库驱动会处理大小写敏感的!
 */

const (
	// 这句sql语句是要给 *sql.DB 执行的!
	createTable = `
create table %[1]s(
  id     bigint unsigned primary key auto_increment,
  p_type varchar(32),
  v0     varchar(255),
  v1 	 varchar(255),
  v2     varchar(255),
  v3     varchar(255),
  v4     varchar(255),
  v5     varchar(255)
);
create index idx_%[1]s on %[1]s (p_type,v0,v1);`

	TruncateTable= "truncate table %s" //truncate table(截断表) 是清空一个表,是彻底删除数据，使其不能进行回滚!
	IsTableExist = "select 1 from %s"
	InsertRow    = "insert into %s (p_type,v0,v1,v2,v3,v4,v5) values(?,?,?,?,?,?,?)"
	DeleteAll    = "delete from %s"
	DeleteByArg  = "delete from %s where p_type = ?"
	SelectAll    = "select * from %s"
	SelectWhere  = "select * from %s where "
)

// Sqlite3
const (
	createTableSqlite3 = `
create table if not exists %[1]s (
	id bigint unsigned primary key auto_increment,
    p_type varchar(32) default '' not null,
    v0 varchar(255) default '' not null,
	v1 varchar(255) default '' not null,
	v2 varchar(255) default '' not null,
 	v3 varchar(255) default '' not null,
	v4 varchar(255) default '' not null,
	v5 varchar(255) default '' not null,
	check (typeof("p_type") = "text" and length("p_type") <= 32),
			
	check (typeof("v0") = "text" and length("v0") <= 255),
	
	check (typeof("v1") = "text" and length("v1") <= 255),
	
    check (typeof("v2") = "text" and length("v2") <= 255),
   
    check (typeof("v3") = "text" and length("v3") <= 255),
	
	check (typeof("v4") = "text" and length("v4") <= 255),
	
	check (typeof("v5") = "text" and length("v5") <= 255)

); create index if not exists idx_%[1]s on %[1]s (p_type,v0,v1);`

	truncateTableSqlite3 = "drop table if exists %[1]s;" + createTableSqlite3
)

// Mysql
const (
	createTableMysql = `
create table if not exists %[1]s(
	id     bigint unsigned primary key auto_increment,
	p_type varchar(32)  default '' not null,
	v0 	   varchar(255) default '' not null,
	v1	   varchar(255) default '' not null,
	v2 	   varchar(255) default '' not null,
	v3     varchar(255) default '' not null,
	v4     varchar(255) default '' not null,
	v5     varchar(255) default '' not null,
	index idx_%[1]s (p_type,v0,v1)
)engine = InnoDB default charset = utf8mb4;`
)

// PostgresSQL
const (
	createTablePostgres = `
create table if not exists %[1]s(
	id     bigint unsigned primary key auto_increment,
	p_type varchar(32)  default '' not null,
	v0     varchar(255) default '' not null,
	v1     varchar(255) default '' not null,
	v2	   varchar(255) default '' not null,
	v3     varchar(255) default '' not null,
	v4     varchar(255) default '' not null,
	v5     varchar(255) default '' not null
); create index if not exists idx_%[1]s on %[1]s (p_type,v0,v1);`

	insertRowPostgres = "insert into %s (p_type,v0,v1,v2,v3,v4,v5) values ($1,$2,$3,$4,$5,$6,$7)"
)

// Sqlserver
const (
	createTableSqlserver = `
create table %[1]s(
	id     bigint unsigned primary key auto_increment,
	p_type nvarchar(32)  default '' not null,
	v0	   nvarchar(255) default '' not null,
	v1     nvarchar(255) default '' not null,
	v2     nvarchar(255) default '' not null,
	v3     nvarchar(255) default '' not null,
	v4     nvarchar(255) default '' not null,
	v5     nvarchar(255) default '' not null
);create index idx_%[1]s on %[1]s (p_type,v0,v1);`
	insertRowSqlserver = "insert into %s (p_type,v0,v1,v2,v3,v4,v5) values (@p1, @p2, @p3, @p4, @p5, @p6, @p7)"
)



